package com.lease.web.admin.schedule;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.lease.model.entity.LeaseAgreement;
import com.lease.model.enums.LeaseStatus;
import com.lease.web.admin.service.LeaseAgreementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.rmi.dgc.Lease;
import java.util.Date;


@Component
public class ScheduleTasks {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void  checkIsLeaseAgreementExpire() {

        LambdaUpdateWrapper<LeaseAgreement> updateWrapper = new LambdaUpdateWrapper<>();
        //将到期的租约状态改为到期，租约状态为已取消的不用修改。
        updateWrapper.lt(LeaseAgreement::getLeaseEndDate, new Date())
                .ne(LeaseAgreement::getStatus, LeaseStatus.CANCELED)
                .set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED);
        System.out.println("正在检查租期是否过期");
        leaseAgreementService.update(updateWrapper);


    }





}
